import {Injectable} from '@angular/core';
import {PageData, User} from "../@core/data/user";
import {Observable} from "rxjs";
import {HttpClient} from "@angular/common/http";
import {NzMessageService} from "ng-zorro-antd/message";

@Injectable({
  providedIn: 'root'
})
export class UserService {

  constructor(private httpClient: HttpClient,
              private messageService: NzMessageService) {
  }

  public getUserList(req: User, pageNumber?: number, pageSize?: number): Observable<PageData> {
    return this.httpClient
      .post<PageData>(`/api/user/getUserList?pageNum=${pageNumber}&pageSize=${pageSize}`, req)
  }

  public getUserById(id: string): Observable<User> {
    return this.httpClient
      .get(`/api/user/getUser/${id}`)
  }

  public editUser(person: User) {
    return this.httpClient
      .put(`/api/user/editUser`, person)
  }

  public addUser(userInfo: User) {
    return this.httpClient
      .post("/api/user/addUser", userInfo)
  }

  public removeUser(uid: string) {
    return this.httpClient
      .delete(`/api/user/removeUser/${uid}`)
  }

  public userLogout() {
    return this.httpClient
      .get("/api/user/logout")
  }

}
